<!doctype html>
<html>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<link type="text/css" rel="stylesheet" href="/css/bootstrap.min.css" />
<link type="text/css" rel="stylesheet" href="/css/ico.css" />
<link type="text/css" rel="stylesheet" href="/css/switch.css" />
<link type="text/css" rel="stylesheet" href="/css/tooltip.css" />
<link type="text/css" rel="stylesheet" href="/css/toPage.css" />
<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/clipboard.min.js"></script>
<script type="text/javascript" src="/js/tooltip.js"></script>
<script type="text/javascript" src="/js/util.js"></script>
<script type="text/javascript" src="/js/toPage.js"></script>
<title>Z盘</title>
<style type="text/css">
#search {
	margin-top: 1em;
}

#search td, #order td, #showMore td {
	width: 6em;
	line-height: 2em;
}

#search, #search input, #search select, #showMore, #showMore input, #showMore select, #order, #order select {
	font-size: 20px;
}

#search select, #showMore select, #order select {
	padding: 0 0 0 0.2em;
}

#search input, #showMore input, #order input {
	width: 100%;
}

.tRight {
	text-align: right;
	padding-right: 0.5em;
}

.tCenter {
	text-align: center;
	padding-right: 0.5em;
}

#fileInfo {
	margin-top: 1em;
}

#fileInfo td {
	vertical-align: middle;
}

#fileInfo input[type="text"] {
	background-color: rgba(255, 255, 255, 0);
	border: solid #c1c1c1 1px;
	width: 100%;
}

#fileInfo .visi {
	visibility: hidden;
}

#fileInfo tr:hover .visi {
	visibility: visible;
}
</style>
<script>
	$(function() {
		initFileInfo();
	});
	function initFileInfo(json, current_page = 1) {
		$("#fileList").empty();
		tips();
		$.ajax({
			url : "",
			type : "post",
			data : json,
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				var list = data.data.files;
				if(list.length==0){
					$("#title").text("文件夹为空！");
					return false;
				}
				$("#title").text(data.data.folderInfo.name);
				var tr,
					id,
					userid,
					name,
					suffix,
					timestamp,
					size,
					uuid,
					description,
					isdelete,
					isshare,
					pwd,
					islimit,
					issearch,
					download,
					browsing,
					date,
					downloadLink,
					isfolder,
					issubfile,
					path,
					md5;
				for (var i in list) {
					id = list[i].id;
					userid = list[i].userid;
					name = list[i].name;
					suffix = (list[i].isfolder == 1) ? "folder" : getFileSuffix(name);
					timestamp = list[i].timestamp;
					size = (list[i].isfolder == 1) ? "" : bytes2Size(list[i].length);
					uuid = list[i].uuid;
					description = list[i].description;
					isdelete = (list[i].isdelete == 1) ? "checked" : "";
					isshare = (list[i].isshare == 1) ? "checked" : "";
					pwd = list[i].pwd;
					islimit = (list[i].islimit == 1) ? "checked" : "";
					issearch = (list[i].issearch == 1) ? "checked" : "";
					download = list[i].download;
					browsing = list[i].browsing;
					date = time2Date(list[i].time);
					downloadLink = "<a class='visi' href='/file/download/" + uuid + "' target='_blank'>下载</a>"
					isfolder = (list[i].isfolder == 1) ? "Y" : "N";
					issubfile = (list[i].issubfile == 1) ? "Y" : "N";
					path = list[i].path;
					md5 = list[i].md5;
					tr = "<tr fileid='" + id + "' userid='" + userid + "' timestamp='" + timestamp + "' name='" + name + "' pwd='" + pwd + "' uuid='" + uuid + "' path='" + path + "' md5='" + md5 + "' isfolder='" + isfolder + "' issubfile='" + issubfile + "'>"
						+ "<td><input type='checkbox' value='" + id + "' name='idcb' /></td>"
						+ "<td>" + userid + "</td>"
						+ "<td><img class='ico ico-" + suffix + "'></td>"
						+ "<td><input type='text' value='" + name + "' /></td>"
						+ "<td><button class='btn btn-primary btn-xs visi' onClick='shareFile()'>分享</button></td>"
						+ "<td>" + size + "</td>"
						+ "<td>" + downloadLink + "</td>"
						+ "<td><input type='text' id='description" + id + "' value='" + description + "' /></td>"
						+ "<td><input type='checkbox' class='switch' id='isdelete" + id + "' " + isdelete + " /></td>"
						+ "<td><input type='checkbox' class='switch' id='issearch" + id + "' " + issearch + " /></td>"
						+ "<td><input type='text' id='pwd" + id + "' value='" + pwd + "' /></td>"
						+ "<td><input type='checkbox' class='switch' id='islimit" + id + "' " + islimit + " /></td>"
						+ "<td><input type='checkbox' class='switch' id='isshare" + id + "' " + isshare + " /></td>"
						+ "<td><input type='text' id='download" + id + "' value='" + download + "' /></td>"
						+ "<td><input type='text' id='browsing" + id + "' value='" + browsing + "' /></td>"
						+ "<td>" + date + "</td>"
						+ "<td><button class='btn btn-success btn-xs visi' onClick='moreInfo()'>更多</button></td>"
						+ "<td><button class='btn btn-warning btn-xs visi' onClick='changeInfo()'>改</button></td></tr>";
					$("#fileList").append(tr);
				}
			}
		});
	}
	function moreInfo() {
		var e = window.event;
		var t = $(e.target || e.srcElement);
		if (tipsTest(t) == true) {
			tips();
			return false;
		}
		var tr = t.parent().parent();
		var id = tr.attr("fileid");
		var userid = tr.attr("userid");
		var isfolder = tr.attr("isfolder");
		var issubfile = tr.attr("issubfile");
		var timestamp = tr.attr("timestamp");
		var path = tr.attr("path");
		var md5 = tr.attr("md5");
		var uuid = tr.attr("uuid");
		$.ajax({
			url : "/admin/user/" + userid,
			type : "post",
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				var d = data.data;
				var u = d.userInfo;
				var account = d.account;
				var name = d.name;
				var gender = d.gender == 1 ? "男" : "女";
				var year = d.year;
				var type = userType2Str(d.type);
				var description = d.description;
				var sizeall = d.sizeall;
				var sizeone = d.sizeone;
				var sizecurrent = d.sizecurrent;
				var time = time2Date(d.time);
				var userinfoid = u.id;
				var type2 = userType2Str(u.type);
				var name2 = u.name;
				var number = u.number;
				var idcard = u.idcard;
				var h = "<table>"
					+ "<tr><td class='tRight'>文件ID</td><td>" + id + "</td></tr>"
					+ "<tr><td class='tRight'>文件夹</td><td>" + isfolder + "</td></tr>"
					+ "<tr><td class='tRight'>子文件</td><td>" + issubfile + "</td></tr>"
					+ "<tr><td class='tRight'>时间戳</td><td>" + timestamp + "</td></tr>"
					+ "<tr><td class='tRight'>文件路径</td><td>" + path + "</td></tr>"
					+ "<tr><td class='tRight'>文件MD5</td><td>" + md5 + "</td></tr>"
					+ "<tr><td class='tRight'>文件UUID</td><td>" + uuid + "</td></tr>"
					+ "<tr><td class='tRight'>&emsp;</td></tr>"
					+ "<tr><td class='tRight'>用户ID</td><td>" + userid + "</td></tr>"
					+ "<tr><td class='tRight'>用户类型</td><td>" + type + "</td></tr>"
					+ "<tr><td class='tRight'>账号</td><td>" + account + "</td></tr>"
					+ "<tr><td class='tRight'>昵称</td><td>" + name + "</td></tr>"
					+ "<tr><td class='tRight'>性别</td><td>" + gender + "</td></tr>"
					+ "<tr><td class='tRight'>出生年</td><td>" + year + "</td></tr>"
					+ "<tr><td class='tRight'>描述</td><td style='max-width:20em;'>" + description + "</td></tr>"
					+ "<tr><td class='tRight'>总容量</td><td>" + sizeall + "MB</td></tr>"
					+ "<tr><td class='tRight'>单文件容量</td><td>" + sizeone + "MB</td></tr>"
					+ "<tr><td class='tRight'>已使用容量</td><td>" + sizecurrent + "MB</td></tr>"
					+ "<tr><td class='tRight'>注册时间</td><td>" + time + "</td></tr>"
					+ "<tr><td class='tRight'>&emsp;</td></tr>"
					+ "<tr><td class='tRight'>实名ID</td><td>" + userinfoid + "</td></tr>"
					+ "<tr><td class='tRight'>实名类型</td><td>" + type2 + "</td></tr>"
					+ "<tr><td class='tRight'>真实姓名</td><td>" + name2 + "</td></tr>"
					+ "<tr><td class='tRight'>学号</td><td>" + number + "</td></tr>"
					+ "<tr><td class='tRight'>身份证号码</td><td>" + idcard + "</td></tr>"
					+ "<tr><td class='tRight'>&emsp;</td></tr>"
					+ "<tr><td class='tRight'>用户信息</td><td><a href='/admin/user/info/" + userid + "'>查询</a></td></tr>"
					+ "<tr><td class='tRight'>实名信息</td><td><a href='/admin/userinfo/info/" + u.id + "'>查询</a></td></tr>"
					+ "<tr><td class='tRight'>所有文件</td><td><a href='/admin/file/user/" + userid + "'>查询</a></td></tr>"
					+ "<tr><td class='tRight'>文件信息</td><td><a href='/admin/file/info/" + id + "'>查询</a></td></tr>"
					+ "<tr><td class='tRight'>浏览记录</td><td><a href='/admin/browsing/info/" + id + "'>查询</a></td></tr>"
					+ "<tr><td class='tRight'>下载记录</td><td><a href='/admin/download/info/" + id + "'>查询</a></td></tr></table>";
				tips(t, h);
			}
		});
	}
	function changeInfo() {
		var e = window.event;
		var t = $(e.target || e.srcElement);
		if (tipsTest(t) == true) {
			tips();
			return false;
		}
		var tr = t.parent().parent();
		var id = tr.attr("fileid");
		var name = $("#name" + id).val();
		var description = $("#description" + id).val();
		var pwd = $("#pwd" + id).val();
		var download = $("#download" + id).val();
		var browsing = $("#browsing" + id).val();
		var isdelete = $("#isdelete" + id).is(":checked") ? "1" : "0";
		var issearch = $("#issearch" + id).is(":checked") ? "1" : "0";
		var islimit = $("#islimit" + id).is(":checked") ? "1" : "0";
		var isshare = $("#isshare" + id).is(":checked") ? "1" : "0";
		$.ajax({
			url : "/admin/edit/file",
			type : "post",
			data : JSON.stringify({
				id : id,
				name : name,
				description : description,
				pwd : pwd,
				download : download,
				browsing : browsing,
				isdelete : isdelete,
				issearch : issearch,
				islimit : islimit,
				isshare : isshare
			}),
			contentType : "application/json;charset=UTF-8",
			dataType : "json",
			success : function(data) {
				tips(t, "修改成功");
			}
		});
	}
</script>
</head>
<body>
	<h1 id="title"></h1>
	<table class="table table-hover table-striped table-condensed table-bordered1" id="fileInfo">
		<thead>
			<tr>
				<th style="width: 2em;">
					<input type="checkbox" id="selectAll">
				</th>
				<th style="width: 4em;">用户ID</th>
				<th style="width: 2em;"></th>
				<th>文件名</th>
				<th style="width: 2em;"></th>
				<th style="width: 4em;">大小</th>
				<th style="width: 3em;"></th>
				<th style="width: 6em;">描述</th>
				<th style="width: 4em;">已删除</th>
				<th style="width: 4em;">已分享</th>
				<th style="width: 4em;">密码</th>
				<th style="width: 4em;">需登录</th>
				<th style="width: 4em;">可搜索</th>
				<th style="width: 4em;">下载量</th>
				<th style="width: 4em;">浏览量</th>
				<th style="width: 11em;">上传时间</th>
				<th style="width: 2em;"></th>
				<th style="width: 2em;"></th>
			</tr>
		</thead>
		<tbody id="fileList"></tbody>
	</table>
</body>
</html>